<?php
class User extends AppModel {
	var $name = 'User';
	var $validate = array(
		'group_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'username' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		
		'password' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Group' => array(
			'className' => 'Group',
			'foreignKey' => 'group_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	
	 //--------- Compare Pass
    function ComparePass(){
        if($this->data['User']['pass']!=$this->data['User']['re_pass']){
            return FALSE;
        }
        else{
            return TRUE;
        }
    }
    
    function ComparePass2(){
        if($this->data['User']['new_password']!=$this->data['User']['confirm_password']){
            return FALSE;
        }
        else{
            return TRUE;
        }
    }
    
    
    
     function hashPasswords($data) {
             if (isset($data['User']['password'])) {
                 $data['User']['password'] = md5($data['User']['password']);
                 return $data;
             }
             return $data;
         }
         
     function hashPassword(){}
    
    function checkCurrentPassword($data){
       //debug($this->id);
        $password = $this->field('password',
                    array('User.id' => $this->id));
        
        //if(md5($data['old_password']) == $this->field('password',array('User.id' => $this->id)))
        return $password === md5($data['old_password']);
    }
    //----- beforeSave
    function beforeSave(){
        $this->hashPassword(NULL,TRUE);
        return TRUE;
    } 
    
    //--- beforeValidate
    function beforeValidate(){
    }

	
}
